<?php /*a:1:{s:101:"E:\hisiphp_cms_1.0\the-first-project---wxcms\thinkphp5.1\tp5\application\admin\view\banner\index.html";i:1616723775;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>轮播图管理</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <b>
            <i>轮播图</i>
        </b>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="user-table" lay-filter="user-table"></table>
    </div>
</div>

<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
    <!--<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>-->
</script>

<script type="text/html" id="user-enable">
   <input type="checkbox" name="{{d.status}}" id="enable" value="{{d.article_id}}"  lay-text="允许轮播|禁止轮播" lay-filter="user-enable"
   {{d.status == 1 ? "checked" : ""}}>
</script>




<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery','common'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;

        let MODULE_PATH = "operate/";

        let cols = [
            [
                {
                    title: '标题',
                    field: 'title',
                    align: 'center',
                },
                {
                    title: '排序',
                    field: 'sort',
                    align: 'center',
                    width: 200
                },
                {
                    title: '禁启',
                    field: 'status',
                    align: 'center',
                    width: 150,
                    templet: '#user-enable'
                 },
                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                    width: 130
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '<?php echo url("admin/banner/getBannerAll"); ?>',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(user-table)', function(obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
            })
            return false;
        });
        /**
         * 修改状态
         */
        form.on('switch(user-enable)', function(obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
            let _this = this;
            $.ajax({
                url : "<?php echo url('admin/banner/updateStatus'); ?>",
                type : "post",
                async : false,
                data : {
                    id : _this.value,
                    status : _this.name
                },
                dataType : "JSON",
                success (res) {
                    if (res.code === 1) {
                        if (_this.name === 1) {
                            $(_this).removeAttr("checked");
                            $(_this).val(0);
                        } else {
                            $(_this).prop("checked",true);
                            $(_this).val(1);
                        }
                    } else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                },
                error (res) {

                }
            });

        });

        window.add = function() {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: "<?php echo url('admin/article/add'); ?>"
            });
        };

        window.edit = function(obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['900px', '600px'],
                content: '<?php echo url("admin/banner/edit"); ?>?id=' + obj.data.article_id
            });
        };

        window.remove = function(obj) {
            layer.confirm('确定要删除该用户', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove/" + obj.data['userId'],
                    dataType: 'json',
                    type: 'delete',
                    success: function(result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

    })
</script>
</body>
</html>
